package com.sanpu.kxe.business.main.view;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.ImageView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.main.contract.CertificateHelpContract;
import com.sanpu.kxe.business.main.contract.MainConfig;
import com.sanpu.kxe.business.main.presenter.CertificateHelpPresenter;
import com.sanpu.kxe.common.interfaces.CommonConfig;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Description：认证照片示例
 * Created by 薛勇军 on 2018/7/20.
 */

public class CertificateHelpActivity extends BaseTitleActivity implements CertificateHelpContract.View {

    @Bind(R.id.exampleIv)
    ImageView exampleIv;

    private CertificateHelpContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_certificate_help;
    }

    @Override
    protected void initView() {
        super.initView();
        commonTitle.setTitle("案例示范");
    }

    @Override
    protected void initData() {
        super.initData();
        String currentType = getIntent().getStringExtra(MainConfig.INTENT_CURRENT_TYPE);
        switch (currentType) {
            case CommonConfig.TYPE_IDFROPIC:
                exampleIv.setImageResource(R.drawable.img_certificate_identity_fro);
                break;
            case CommonConfig.TYPE_IDCONPIC:
                exampleIv.setImageResource(R.drawable.img_certificate_identity_con);
                break;
            case CommonConfig.TYPE_IDHANDPIC:
                exampleIv.setImageResource(R.drawable.img_certificate_identity_hand);
                break;
            case CommonConfig.TYPE_CRDFROPIC:
                exampleIv.setImageResource(R.drawable.img_certificate_bank_fro);
                break;
            case CommonConfig.TYPE_CRDCONPIC:
                exampleIv.setImageResource(R.drawable.img_certificate_bank_con);
                break;
        }
        mPresenter = new CertificateHelpPresenter(this, currentType);
    }

    @OnClick({R.id.takePicRtv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.takePicRtv:
                mPresenter.checkPermission();
                break;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                           @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        switch (requestCode) {
            case CommonConfig.REQUESTCODE_CERTIFICATE_HELP: {
                if (grantResults.length > 0
                        && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    mPresenter.checkPermission();
                }
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mPresenter.onActivityResult(requestCode, resultCode);
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    public void setPresenter(CertificateHelpContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
